#include "TaskQueue.h"


TaskQueue::TaskQueue(size_t queSize)
:_quesize(queSize)
,_que()
,_mutex()
,_notEmpty()
,_notFull()
{}

TaskQueue::~TaskQueue(){

};
    
void TaskQueue::push(const int & value){
    unique_lock<mutex> ul(_mutex);
    while(full()){
        _notFull.wait(ul);
    }
    _que.push(value);
    _notEmpty.notify_one();
};

int TaskQueue::pop(){
    unique_lock<mutex> ul(_mutex);
    while(empty()){
        _notEmpty.wait(ul);
    }
    int tmp = _que.front();
    _que.pop();
    _notFull.notify_one();
    return tmp;
};

bool TaskQueue::empty()const{
    return _que.size() == 0;
};

bool TaskQueue::full()const{
    return _que.size() == _quesize;
};

